package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Admin;
import dao.AdminDAO;


public class UpdataAdminServlet extends HttpServlet {


	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html; charset=UTF-8");
		request.setCharacterEncoding("utf-8");
		HttpSession session=request.getSession();
		PrintWriter out = response.getWriter();
		
		int id=Integer.parseInt(request.getParameter("id"));
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		int kind =1;
		
		Admin Admin = new Admin();

		Admin.setUsername(username);
		Admin.setPassword(password);
		Admin.setKind(kind);
		
		AdminDAO Admindao=new AdminDAO();
		
		int i = Admindao.UpdataAdmin(Admin, id);

		
		if(i>0)
		{
			out.print("<script>alert('操作成功！');location.href='admin/admin_updata.jsp?id="+ id +"';</script>");
		}
		else
		{
			out.print("<script>alert('操作失败！');history.go(-1);</script>");
		}
		
		
		
	}

}
